home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10141 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: Inter.NL.net!usenet
  2. From: Auke.Reitsma@net.HCC.nl (Auke Reitsma)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help needed - fgets and EOF
  5. Date: Fri, 15 Mar 1996 18:56:32 GMT
  6. Organization: Inter.NL.net, The Internet Provider in The Netherlands.
  7. Message-ID: <4icer9$df5@altrade.nijmegen.inter.nl.net>
  8. References: <Do2y8w.K8v@murdoch.acc.Virginia.EDU>
  9. Reply-To: Auke.Reitsma@net.HCC.nl
  10. NNTP-Posting-Host: rt99-4.rotterdam.nl.net
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. brr7q@virginia.edu wrote:
  14.  
  15. > Hi
  16.  
  17. > I wrote what I thought would be a simple application (DOS).  It reads lines
  18. > from a file character by character using fgets.  I check each character
  19. > for and newline (\n) and EOF.  The program works as long as the file
  20. > has lf at the end of the last record, BUT, if the last record does not
  21. > end with a <lf> then the program bombs.  When debugging my code I 
  22. > find that the last character read in is hex ff (255 ascii).  I trap this to signal 
  23. > the end of the process, but the program still bombs.  It doesn't bomb 
  24. > untill it closes all the files and is just ready to exit the program. 
  25.  
  26. > What I need to know is what is causing this bomb.  The situation arises when a 
  27. > data file has been edited but the last line does not end with a lf.
  28.  
  29. Without code I can't really say anything about it, but the most common
  30. mistake by beginners is assuming that EOF is reached when they have read
  31. all data. 
  32. EOF is ONLY detected AFTER you try to read PAST the end of the file ...
  33.  
  34.  
  35. Greetings from Delft, The Netherlands.
  36.  
  37. Auke Reitsma
  38.  
  39.